// window.addEventListener('load', yourFunction, false);
// "use strict"
// {
//     var x = 1;
//     let a = 3;
//     const b = 4;
// }
// var i;
// var arry = [1, 23, 4];

// for (i in arry) {
//     var y = 9;
//     console.log(arry[i]);
// }


// console.log(y);



// function add(z, y) {
//     if (z > 0) {
//         var x = 1;
//         let a = 3;
//         const b = 4;
//     }
//     console.log(a);
//     return z + y;
// }
// console.log(add(1, 2));

// let x = 10;
// {
//     let x = 2;
//     // console.log(x);
// }
// console.log(x);

// var y = 0;
// {
//     var y = 8;
// }
// console.log(y);

//循环打印 i
// var i = 5;
// for (var i = 0; i < 10; i++) {

// }
// console.log(i);

//const 关键字
// const PI = 3.14;
// {
//     const i = 1;

// }
// const i = 2;
// console.log(i);

const car = { type: "First", age: 12, name: "kk" };
car.age = 45;
car.type = "low";
car.name = "oo";
//console.log(car.type, car.age, car.name);

//json 里面的 JSON.parse();???????? 是将字符串数据转换为js对象；
// {
//     "name": "kk",
//         "age": 12,
//             "sex": "f"
// }

// var obj = JSON.parse('{    "name": "kk",
// "age": 12,
//     "sex": "f"
// }');
var person = '{name:"kk", age:12, sex:"f"}';  //这是字符串数据；
// var obj = JSON.parse(person);   //把字符串解析成js对象；
//console.log(obj);    //???为何解析不了呢？

//js对象转换为字符串
var person_1 = { name: "kk", age: 12, sex: "f" };
var obj_1 = JSON.stringify(person_1);
//console.log(obj_1);   ///???

function func() {
    var a, b, c;
    a = void (b = 5, c = 7);
}
// console(a, b, c);

function print() {
    var z = "jjj";
    // console.log(z);
}
setTimeout(print, 3000);

setTimeout(function () {
    // console.log("First");
    setTimeout(function () {
        // console.log("second");
        setTimeout(function () {
            // console.log("third");
        }), 2000
    }), 3000
})

print(1000, "First").then(function () {
    return print(4000, "second");
}).then(function () {
    print(3000, "Third");
})

function print(delay, message) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            // console.log(message);
            resolve();
        }, delay);
    });
}

async function asyncFunc() {
    await print(1000, "First");
    await print(4000, "second");
    await print(1000, "Third");


}

new Promise(function (resolve, reject) {
    // console.log("run");
})

new Promise(function (resolve, reject) {
    var a = 0;
    var b = 1;
    if (b == 0)
        reject("Divide zero");
    else
        resolve(a / b);
}).then(function (value) {
    // console.log("a / b = " + value);
}).catch(function (err) {
    // console.log(err);
}).finally(function () {
    // console.log("End");
})

function myfunction(a, b) {
    return a * b;
}

var q = function (a, b) { return a + b };
var w = q(2, 3);
// console.log(w);

//内置的函数构造器,new Function("参数1","参数2","参数3");
var myfunction = new Function("a", "b", "return a + b");
var e = myfunction(3, 4);
// console.log(e);

var myfunction = function (a, b) { return a + b };
var r = myfunction(4, 3);
// console.log(r);

//自己调用自己的函数???
(function () {
    var x = "hello";
})();
// console.log(x);  //???

//函数可以作为一个值使用，也可以作为一个表达式使用，因为函数里通过return语句返回来的是一个值；
//函数是对象，它有属性和方法，arguments.length属性是返回函数调用过程中的参数个数；
//tostring()方法将函数作为一个字符串返回；

//箭头函数使函数写起来更简洁；
//before
var t = function myfunction(q, v) { return q + v };
var y = t(3, 4);

//after
var x = (q, v) => q + v;   //非常简便
var x = (q, v) => { return q + v };
// console.log(x(3, 3));

var object = "hello";
var z = object.length;
console.log(z);

//window location 7.22
// console.log(location.href);  //是返回当前页面的url，也就是html页面的url,也就是jianshu-log-on.html的url;
// console.log(location.pathname); //返回当前页面的路径和文件名；

// //window.navigator
// console.log(navigator.appCodeName);  //浏览器代号
// console.log(navigator.appName);  //浏览器名称
// console.log(navigator.appVersion);
// console.log(navigator.cookieEnabled);


//window.alert()


//7.22 string
//字符串中查找字符串
//比如说，想在this is an example.中找到is 出现的位置；
var stringIndexOf = "This is an example.";
console.log(stringIndexOf.indexOf("is"));  // 2 控制台打印出在第二个位置，即第三个元素；
console.log(stringIndexOf.indexOf("an"));
console.log(stringIndexOf.indexOf("An"));
console.log(stringIndexOf.lastIndexOf("is"));  //5

//match
var stringMatch = "This is an example.";
console.log(stringMatch.match("is"));
console.log(stringMatch.match("is"));
console.log(stringMatch.match("is"));
console.log(stringMatch.match("This"));
console.log(stringMatch.match("This"));


console.log(stringMatch.match("Is"));

//string replace()
var stringReplace = "This is an example";
var n = stringReplace.replace("is", "an");
var m = stringReplace.replace("is", "an");
console.log(n); //一条语句只能替换第一个出现的字符串；
console.log(m);

//string toUpperCase() & string toLowerCase()
var stringToUpperCase = "This is an example";
var stringToUpperCase = new String("This is an example.");
var m = stringToUpperCase.toUpperCase();  //全部都转化成大写；（）里面没有参数
var n = stringToUpperCase.toLowerCase();  //全部都转化成小写；（）里面没有参数
console.log(m);
console.log(n);

//string split 字符串转为数组
var stringSplit = "This,is,an,example";
var n = stringSplit.split(",");
console.log(n);
console.log(n[0]);
console.log(n[1]);

// string constructor属性  
var stringConstructor = "This is an example";
console.log(stringConstructor.constructor);  //返回对string对象属性 创建的函数；
console.log(stringConstructor.length);  //返回字符串长度；

//string prototype 属性  
//object.prototype.name = value;
var stringPrototype = "This is an example";
function employee(name, age, sex) {
    this.name = name;
    this.age = age;
    this.sex = sex;
}
var fred = new employee("keke", 13, "f");
employee.prototype.sno = null;
fred.sno = "11234";
console.log(fred.sno);

//给employee对象添加 born 属性；
var fred_1 = new employee("uu", 10, "m");
employee.prototype.born = null;
fred_1.born = "1999";
console.log(fred_1.born);

//charAt()方法用于返回指定位置的字符
var stringCharAt = "This is an example.";
console.log(stringCharAt.charAt(0));
console.log(stringCharAt.charAt(2));
console.log(stringCharAt.charCodeAt(0));
console.log(stringCharAt.concat("is", "a"));
//console.log(concat("is", "a"));  这样写是不行的；
var string_1 = "I think";
var string_2 = "it is.";
console.log(stringCharAt.concat(string_1, string_2));

//fromCharCode();  ???为啥这个显示不出来？？？
// console.log(StringCharAt.fromCharCode(65));
// console.log(fromCharCode(65));
// console.log(String.fromCharCode(65));
// var n = String.fromCharCode(65, 72);
// console.log(n);


//includes()
var str = "This is an example.";
console.log(str.includes("is"))
//match()
console.log(str.match(/is/g));  //区分大小写
console.log(str.match(/is/gi)); //不区分大小写

//repeat()
console.log(str.repeat(3));

//replace("","");
console.log(str.replace("is", "a"));
console.log(str.replace("/is/g", "a"));  //执行把全部 is 替换为 a
console.log(str.replace("/is/gi", "a"));  //执行全局替换，且忽略大小写；替换成 a

//replaceAll()
// console.log(str.replaceAll("is", "lllll"));

//RegExp()
// var patt = new RegExp(pattern, modifiers);
// var patt = /patten/modifiers;  //更为简单的描述方式；
// console.log(str.match(/is/i));

function add(x, y) {
    return x + y;
}

console.log(add(1, 2))

var fff = add;

console.log(fff)